package com.zzx.boot.utils;

import com.zzx.boot.entity.table.LoginUser;
import org.springframework.security.core.context.SecurityContextHolder;

/**
 * @author tan
 * @version 1.0
 * @date 2023/7/9 13:37
 */
public class SecurityUtils {

    public static LoginUser getLoginUser(){
        return (LoginUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    }

    public static Long getUserId(){
        return getLoginUser().getUser().getId();
    }

    /**
     * true 表示登录
     * @return
     */
    public static boolean isLogin(){
        return !(SecurityContextHolder.getContext().getAuthentication().getPrincipal().equals("anonymousUser"));
    }


}
